﻿using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 插入数据专用 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.FileUpload1.HasFile == false)
        {
            Response.Write("<script>alert('请选择文件！！');</script>");
            return;

        }

        if (TextBox2.Text == "" || content.Text == "" || TextBox3.Text == "" || DropDownList2.SelectedItem.Text == "" || TextBox6.Text == "" ||TextBox1.Text == "" || TextBox4.Text=="")
        {
            Response.Write("<script>alert('请填写完整老师信息！！！！!');</script>");
            return;
        }
        if (TextBox5.Text == "")
        {
            Response.Write("<script>alert('请输入你所要替换的老师名字！！！!');</script>");
            return;
        }
        string name = FileUpload1.FileName;
        string type = name.Substring(name.LastIndexOf(".") + 1);
        string ipath = Server.MapPath("~/images/") + "\\" + name;
        string wpath = "images//" + name;
        //string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
        //strConnection += @"Data Source=E:\关于编程\zuoye\web.mdb";
        string strConnection = "Provider=Microsoft.Jet.OleDb.4.0 ;Data Source=|DataDirectory|\\web.mdb";
        OleDbConnection objConnection = new OleDbConnection(strConnection);
        objConnection.Open();
        string query1 = "update ty_teacher set ty_pic='" + wpath + "',ty_name='" + TextBox2.Text.Trim() + "',ty_message='" + content.Text.Trim() + "',ty_job='" + TextBox4.Text.Trim() + "',ty_sex='" + DropDownList2.SelectedItem.Text.Trim() + "',ty_mingzhu='" + TextBox1.Text.Trim() + "',ty_addr='" + TextBox6.Text.Trim() + "',ty_maj='" + TextBox3.Text.Trim() + "' where ty_name='" + TextBox5.Text.Trim() + "'";
        OleDbCommand cmd = new OleDbCommand(query1, objConnection);
        if (type == "jpg" || type == "gif" || type == "bmp" || type == "png")
        {
            FileUpload1.SaveAs(ipath); //服务器保存路径  

            cmd.ExecuteNonQuery();
            objConnection.Close();
            Response.Write("<script>alert('提交成功');</script>");
            Image1.ImageUrl = wpath;
        }
        else
            Response.Write("<script>alert('只能上传图片哦！！！!');</script>");
       // Response.AddHeader("Refresh", "0");  //刷新页面，并从新执行页面内容！
    }
}
